from time import time

def file_to_list(filename: str) -> list[int]:
    if filename.endswith(".txt"):
        file = open(filename, 'r')
    else:
        file = open(f"{filename}.txt", 'r')
    
    data = [int(number) for number in file]

    file.close()

    return data


def bubble_sort(numbers: list[int]) -> int:
    start = time()
    for i in range(len(numbers)):
        for j in range(i, len(numbers) - 1):
            if numbers[j] > numbers[j + 1]:
                numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j]
    end = time()

    return round((end - start) * 1000)

list1 = file_to_list("m1_sorted")
list2 = file_to_list("m2_reverse")
list3 = file_to_list("m3_shuffle")

result_n1 = bubble_sort(list1)
result_n2 = bubble_sort(list2)
result_n3 = bubble_sort(list3)

print(f"m1_sorted {result_n1} milliseconds",
       f"m2_reverse {result_n2} milliseconds",
         f"m3_shuffle {result_n3} milliseconds", sep="\n")


